package py.owner.log.format;

import org.apache.commons.lang3.StringUtils;

public abstract class AbstractLogFormat implements LogFormat{

    /**
     * 日志标题
     */
    protected String title;

    public AbstractLogFormat(String title) {
        this.title = title;
    }

    private String getTitle() {
        StringBuilder sb = new StringBuilder(32);
        if (StringUtils.isNotBlank(title)) {
            sb.append("[").append(title).append("]。");
        }
        return sb.toString();
    }

    /**
     * 获取Log格式
     *
     * @return
     */
    @Override
    public String log() {
        return getTitle() + buildLogMsg();
    }

    /**
     * 子类实现
     *
     * @return
     */
    protected abstract String buildLogMsg();
}
